package com.hy.${packageCode}.common.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.extern.jackson.Jacksonized;

import java.util.Objects;

@Getter
@Builder
@Jacksonized
@AllArgsConstructor(onConstructor_ = {@JsonCreator})
public class PointDTO {


    private double x;
    private double y;

    // 代表两条直线没有交点
    public static final PointDTO NONE = PointDTO.builder().build();

    // 代表两条直线无限多个交点（重合）
    public static final PointDTO INFINITE = PointDTO.builder().build();

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        PointDTO pointDTO = (PointDTO) o;
        return x == pointDTO.x && y == pointDTO.y;
    }

    @Override
    public int hashCode() {
        return Objects.hash(x, y);
    }

    public static PointDTO of(double x, double y) {
        return PointDTO.builder().x(x).y(y).build();
    }

    @Override
    public String toString() {
        return "(" + x + ", " + y + ")";
    }
}
